﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace JTTD.Common.Helper
{
    /// <summary>
    /// 获取json配置文件工具类
    /// </summary>
    public static class ConfigHelper
    {
        /// <summary>
        /// 获取指定json配置文件的指定节点
        /// </summary>
        /// <param name="key"></param>
        /// <param name="jsonFileName"></param>
        /// <returns></returns>
        public static string GetConfigValue(string key,string jsonFileName= "appsettings.json")
        {
            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(jsonFileName, optional: true, reloadOnChange: true);
            IConfigurationRoot configuration = builder.Build();
            return configuration.GetSection(key).Value;
        }

    }
}
